Android 分享文件
插件 ID: 25220
来源: https://ext.dcloud.net.cn/plugin?id=25220
实现分享任意文件到其它应用,文本、图片、视频、文件,兼容uniapp/uniappx
更新记录
1.0.1(2025-12-22)
优化
1.0.0(2025-09-22)
初始化
平台兼容性
uni-app(4.06)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 | | | √ | √ |
- |
- | √ | √ | 5.0 |
- |
- | | | 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 | | |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- | |
uni-app x(4.06)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 | | |
- |
- | 5.0 |
- |
- |
- | |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | | | √ | √ | √ | |
xtf-share
uniappx
<template>
<view>
<button style="margin: 10rpx;" type="primary" @click="onClick(0)">分享文本</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(1)">分享图片</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(2)">分享视频</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(3)">分享文件</button>
<image :src="p"></image>
</view>
</template>
<script>
import { shareText,shareImage, shareVideo, shareFile } from '@/uni_modules/xtf-share';
export default {
data() {
return {
title: 'Hello',
p:"",
}
},
onLoad() {
},
methods: {
onClick(id:number){
var that=this;
if(id==0){
shareText("title","xtf")
}else if(id==1){
uni.chooseImage({
count: 2,
success: (res) => {
console.log("this.imageList: ",res)
shareImage("xxx",res.tempFilePaths);
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
}
})
}else if (id==2){
uni.chooseVideo({
success: (res) => {
console.log("this.imageList: ",res)
shareVideo("xxx",[res.tempFilePath] as string[] );
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
}
})
}else if(id==3){
uni.chooseFile({
count:1,
success:(res)=> {
shareFile("xtf",res.tempFilePaths);
}
})
}
}
}
}
</script>
<style>
.logo {
height: 100px;
width: 100px;
margin: 100px auto 25px auto;
}
.title {
font-size: 18px;
color: #8f8f94;
text-align: center;
}
</style>uniapp
<template>
<view>
<button style="margin: 10rpx;" type="primary" @click="onClick(0)">分享文本</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(1)">分享图片</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(2)">分享视频</button>
<button style="margin: 10rpx;" type="primary" @click="onClick(3)">分享文件</button>
<image :src="p"></image>
</view>
</template>
<script>
import { shareText,shareImage, shareVideo, shareFile } from '@/uni_modules/xtf-share';
export default {
data() {
return {
title: 'Hello',
p:"",
}
},
onLoad() {
},
methods: {
onClick(id){
var that=this;
if(id==0){
shareText("title","xtf")
}else if(id==1){
uni.chooseImage({
count: 2,
success: (res) => {
console.log("this.imageList: ",res)
shareImage("xxx",res.tempFilePaths);
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
}
})
}else if (id==2){
uni.chooseVideo({
success: (res) => {
console.log("this.imageList: ",res)
shareVideo("xxx",[res.tempFilePath] as string[] );
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
}
})
}else if(id==3){
uni.chooseFile({
count:1,
success:(res)=> {
shareFile("xtf",res.tempFilePaths);
}
})
}
}
}
}
</script>
<style>
.logo {
height: 100px;
width: 100px;
margin: 100px auto 25px auto;
}
.title {
font-size: 18px;
color: #8f8f94;
text-align: center;
}
</style>